/// <reference path="./typings/index.d.ts" />
'use strcit';
const gulp = require('gulp');
const $ = require('gulp-load-plugins')();
const bsync = require('browser-sync');
const run = require('run-sequence');
const reload = bsync.reload;
gulp.task('sass', function() {
    $.rubySass('./app/styles/**.scss')
        .on('error', $.rubySass.logError)
        .pipe(gulp.dest('./app/styles/'))
        .pipe(reload({
            stream: true
        }))
});
gulp.task('app:js&html', function() {
    gulp.src(['./app/**/*.js', './app/**/*.html'])
        .pipe(reload({
            stream: true
        }))
});

gulp.task('watch', function() {
    gulp.watch('./app/styles/**.scss', ['sass']);
    gulp.watch(['./app/**/*.js', './app/**/*.html'], ['app:js&html']);
});

gulp.task('app:server', () => {
    bsync.init({
        server: {
            baseDir: "./app/"
        }
    });
});
gulp.task('app', (cb) => {
    run(['sass', 'app:server', 'watch'], cb);
});
gulp.task('develop', function() {
    livereload.listen();
    nodemon({
        script: 'bin/www',
        ext: 'js ejs coffee',
        stdout: false
    }).on('readable', function() {
        this.stdout.on('data', function(chunk) {
            if (/^Express server listening on port/.test(chunk)) {
                livereload.changed(__dirname);
            }
        });
        this.stdout.pipe(process.stdout);
        this.stderr.pipe(process.stderr);
    });
});

gulp.task('default', [
    'sass',
    'develop',
    'watch'
]);